package tc.de.krawallmann.gravoblocks.game.model;

import java.security.SecureRandom;
import java.util.Random;

/**
 * A factory for creating Tile objects.
 * 
 * @author KrawallMann
 * @version 1.1
 */
public final class TileFactory {

	/**
	 * Creates a new Tile object.
	 * 
	 * @param rotation
	 *            the rotation
	 * @param shape
	 *            the shape
	 * @return the tetris tile
	 */
	public static TetrisTile createTile(final int rotation, final TileShape shape) {
		return new TetrisTile(shape, rotation);
	}

	/**
	 * Generate random tile.
	 * 
	 * @param specialTiles
	 * @return the tetris tile
	 */
	public static TetrisTile generateRandomTile(final boolean specialTiles) {
		final Random random = new SecureRandom();
		TetrisTile ret;
		do {
			ret =
					TileFactory.createTile(random.nextInt(4),
							TileShape.values()[random.nextInt(TileShape.values().length)]);
		} while (!specialTiles
				&& (ret.getShape().equals(TileShape.TYPE_PLUS)
						|| ret.getShape().equals(TileShape.TYPE_U) || ret.getShape().equals(
						TileShape.TYPE_V)));
		return ret;
	}

	/**
	 * Singleton constructor!.
	 */
	private TileFactory() {
		// Singleton constructor!
	}
}
